#pragma once

#include <ctype.h>

namespace arduino_basic {

    // Checks for an alphanumeric character.
    // It is equivalent to (isalpha(c) || isdigit(c)).
    constexpr bool isAlphaNumeric(int c) {
        return (isalnum(c) == 0 ? false : true);
    }


    // Checks for an alphabetic character.
    // It is equivalent to (isupper(c) || islower(c)).
    constexpr bool isAlpha(int c) {
        return (isalpha(c) == 0 ? false : true);
    }


    // Checks whether c is a 7-bit unsigned char value
    // that fits into the ASCII character set.
    constexpr bool isAscii(int c) {
        return (isascii(c) == 0 ? false : true);
    }


    // Checks for a blank character, that is, a space or a tab.
    constexpr bool isWhitespace(int c) {
        return (isblank(c) == 0 ? false : true);
    }


    // Checks for a control character.
    constexpr bool isControl(int c) {
        return (iscntrl(c) == 0 ? false : true);
    }


    // Checks for a digit (0 through 9).
    constexpr bool isDigit(int c) {
        return (isdigit(c) == 0 ? false : true);
    }


    // Checks for any printable character except space.
    constexpr bool isGraph(int c) {
        return (isgraph(c) == 0 ? false : true);
    }


    // Checks for a lower-case character.
    constexpr bool isLowerCase(int c) {
        return (islower(c) == 0 ? false : true);
    }


    // Checks for any printable character including space.
    constexpr bool isPrintable(int c) {
        return (isprint(c) == 0 ? false : true);
    }


    // Checks for any printable character which is not a space
    // or an alphanumeric character.
    constexpr bool isPunct(int c) {
        return (ispunct(c) == 0 ? false : true);
    }


    // Checks for white-space characters. For the avr-libc library,
    // these are: space, formfeed ('\f'), newline ('\n'), carriage
    // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
    constexpr bool isSpace(int c) {
        return (isspace(c) == 0 ? false : true);
    }


    // Checks for an uppercase letter.
    constexpr bool isUpperCase(int c) {
        return (isupper(c) == 0 ? false : true);
    }


    // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
    // 8 9 a b c d e f A B C D E F.
    constexpr bool isHexadecimalDigit(int c) {
        return (isxdigit(c) == 0 ? false : true);
    }


    // Converts c to a 7-bit unsigned char value that fits into the
    // ASCII character set, by clearing the high-order bits.
    constexpr int toAscii(int c) {
        return toascii(c);
    }


    // Warning:
    // Many people will be unhappy if you use this function.
    // This function will convert accented letters into random
    // characters.

    // Converts the letter c to lower case, if possible.
    constexpr int toLowerCase(int c) {
        return tolower(c);
    }


    // Converts the letter c to upper case, if possible.
    constexpr int toUpperCase(int c) {
        return toupper(c);
    }

}  // namespace arduino_basic